﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="pol_soiduk_vastus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(PolSoidukVastus))]
    public class PolSoidukVastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IPolSoidukVastus clazz;
        
        public PolSoidukVastusSerializer(IPolSoidukVastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("kood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Kood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("teade");
            if (clazz.Teade!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Teade))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Teade");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("soiduk");
            if (clazz.Soiduk!=null) {
                global::Xtee.Core.SerializationMetadata metaSoiduk = this.GetMetaData(clazz.Soiduk);
                Writer.WriteTypeAttribute(metaSoiduk.TypeQualifiedName.Namespace, metaSoiduk.TypeQualifiedName.Name);
                metaSoiduk.NewSerializer(clazz.Soiduk).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Soiduk");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "kood")) {
                goto kood;
            }
            else {
                if ((Reader.LocalName == "teade")) {
                    goto teade;
                }
                else {
                    if ((Reader.LocalName == "soiduk")) {
                        goto soiduk;
                    }
                    else {
                        return;
                    }
                }
            }
        kood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pol_soiduk_vastus>kood");
            }
            clazz.Kood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kood")).Value;
            goto START;
        teade:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pol_soiduk_vastus>teade");
            }
            clazz.Teade = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("teade")).Value;
            goto START;
        soiduk:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>pol_soiduk_vastus>soiduk");
            }
            global::Xtee.Core.SerializationMetadata metaSoiduk = this.GetMetaData<PolSoidukVastus.ISoidukType>(Reader, ">>pol_soiduk_vastus>soiduk", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
            clazz.Soiduk = metaSoiduk.NewEntity<PolSoidukVastus.ISoidukType>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("soiduk");
                metaSoiduk.NewSerializer(clazz.Soiduk).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>pol_soiduk_vastus>soiduk", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(PolSoidukVastus.SoidukType))]
        public class SoidukTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected PolSoidukVastus.ISoidukType clazz;
            
            public SoidukTypeSerializer(PolSoidukVastus.ISoidukType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.Soiduk != null) 
                            && (x < clazz.Soiduk.Count)); x = (x + 1)) {
                    if (clazz.Soiduk[x]!=null) {
                        Writer.WriteStartElement("soiduk");
                        global::Xtee.Core.SerializationMetadata metaSoiduk = this.GetMetaData(clazz.Soiduk[x]);
                        Writer.WriteTypeAttribute(metaSoiduk.TypeQualifiedName.Namespace, metaSoiduk.TypeQualifiedName.Name);
                        metaSoiduk.NewSerializer(clazz.Soiduk[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="soiduk") {
                    clazz.Soiduk = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IPolSoiduk>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "soiduk")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>pol_soiduk_vastus>soiduk>soiduk");
                        }
                        global::Xtee.Core.SerializationMetadata metaSoiduk = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IPolSoiduk>(Reader, "pol_soiduk", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                        global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IPolSoiduk item = metaSoiduk.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IPolSoiduk>();
                        clazz.Soiduk.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("soiduk");
                            metaSoiduk.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
